﻿var CSP_HomeRight = {
    Register: function () {
        var url = window.location.href;
        window.location.href = "/UCenter/Register.aspx?urlback=" + encodeURI(url);
    },
    Login: function () {
        var url = window.location.href;
        window.location.href = "/UCenter/Login.aspx?urlback=" + encodeURI(url);
    },

    SearchValue: function () {
        var serviceAge = "";
        var city = encodeURI($("#Txt_City").val());
        var county = encodeURI($("#Txt_County").val());
        var searchValue = encodeURI($("#Txt_SearchValue").val());
        if (!isNaN($("#Txt_Age").val())) {
            serviceAge = $("#Txt_Age").val();
        }

        if (serviceAge == "" && city == "" && county == "" && searchValue == "") {
            return;
        }


        var url = window.location.pathname+"?HomeRight=1&HomeRightServiceAge=" + serviceAge + "&HomeRightCity=" + city + "&HomeRightCounty=" + county;

        $.ajax({
            url: url,
            type: "get",
            dataType: "json",
            cache: false,
            success: function (data, status, jhr) {
                //data  {Age:1,AreaId:"16"}
                var urlparm = "";
                var split = "";
                if ((city != "" || county != "") && data.AreaId != null) {
                    urlparm += split + "sa" + data.AreaId;
                    split = "-"
                }
                if (serviceAge != "") {
                    urlparm += split + "a" + data.Age;
                    split = "-"
                }
                if (split != "") {
                    urlparm + "/"
                }

                if (searchValue.trim() != "") {
                    urlparm += "?searchValue=" + searchValue;
                }
                window.location.href = "/search/" + urlparm;
            }
        });
    }
};